<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#228fbd"
      text-color="#fff"
      active-text-color="#ffd04b"
      v-loading="loding"
      @select="menuItmeSelect"
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template #title>
              <i :class="item.icon"></i>
              <span :title="item.title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template #title>
                  <i :class="subItem.icon"></i>
                  <span :title="subItem.title">{{ subItem.title }}</span>
                </template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                >
                  <template #title>
                    <i :class="threeItem.icon"></i>
                    <span :title="threeItem.title">{{ threeItem.title }}</span>
                  </template>
                </el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                <template #title>
                  <i :class="subItem.icon"></i>
                  <span :title="subItem.title">{{ subItem.title }}</span>
                </template>
              </el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <template #title>
              <span :title="item.title">{{ item.title }}</span>
            </template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: [],
      loding: true,
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    },
    collapse() {
      return this.$store.state.collapse;
    },
  },
  mounted() {},
  methods: {
    menuItmeSelect(key) {
      this.$router.push({
        path: key,
      });
    },
    initMenu(items) {
      this.items = items;
      this.loding = false;
    },
  },
};
</script>

<style scoped lang="less">
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 50px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
.el-menu-item {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  i {
    color: #fffffb;
  }
}
.el-submenu__title {
  color:#fff;
  i {
    color: #fffffb;
    .el-submenu__icon-arrow {
      color: #fffffb;
    }
  }
} 
.el-submenu__title i {
    color: #fffffb;
}
</style>
